<?php
// +----------------------------------------------------------------------
// | 小牛Admin
// +----------------------------------------------------------------------
// | Website: www.xnadmin.cn
// +----------------------------------------------------------------------
// | Author: dav <85168163@qq.com>
// +----------------------------------------------------------------------

namespace app\admin\controller\curd\service;

class BuildColumn
{
    public function buildHead($data)
    {
        $html = '';
        foreach ($data as $_data) {
            if ($_data['column'] == 1) {
                $html .=<<<php
                    <th>{$_data['name']}</th>
php;
                $html .= PHP_EOL;
            }
        }
        $html = trim($html);
        return $html;
    }

    public function buildBody($data)
    {
        $html = '';
        foreach ($data as $_data) {
            if ($_data['column'] == 1) {
                if ($_data['form_type'] == 'image') {
                    $html .=<<<php
                    <td><img src="{###vo.{$_data['field']}}" data-bigimg="{###vo.{$_data['field']}}" class="xn_img"></td>
php;
                    $html .= PHP_EOL;
                } else {
                    $html .=<<<php
                    <td>{###vo.{$_data['field']}}</td>
php;
                    $html .= PHP_EOL;
                }
            }
        }
        $html = str_replace('###', '$', $html);
        $html = trim($html);
        return $html;
    }

    public function buildLayuiColumn($data)
    {
        $html = '';
        foreach ($data as $_data) {
            if ($_data['column'] == 1) {
                if ($_data['form_type'] == 'image') {
                    $html .=<<<php
                {field:'{$_data['field']}', title: '{$_data['name']}', templet: function(d){
                    return '<img src="'+d.{$_data['field']}+'" data-bigimg="'+d.{$_data['field']}+'" class="xn_img"  lay-on="xn_img">';
                }},
php;
                } else {
                    $html .=<<<php
                {field:'{$_data['field']}', title: '{$_data['name']}'},
php;
                }
                $html .= PHP_EOL;
            }
        }
        $html = trim($html);
        return $html;
    }
}
